package com.lvwenguo.controller;

import com.lvwenguo.utils.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/*
* 用于初始化数据
* */
@WebServlet(urlPatterns = "/JdbcUtilServlet",loadOnStartup = 0)
public class JdbcUtilServlet extends HttpServlet {

    @Override
    public void init() throws ServletException {
        super.init();
        try {
        System.out.println("开始加载配置文件");

        InputStream inputstream = JdbcUtil.class.getResourceAsStream("/jdbc.properties");
        Properties properties=new Properties();
        properties.load(inputstream);
        JdbcUtil jdbcUtil=JdbcUtil.getJdbcUtil();
        jdbcUtil.initGetConnertion(properties);
        System.out.println("结束加载配置文件");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
